package com.xpec.c4.service.module.datacenter.account;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ms.service.module.account.Account;
import com.ms.service.module.account.db.AccountDAO;
import com.xpec.c4.game.datamanager.ResultNo;
import com.xpec.c4.game.utility.GameUtility;
import com.xpec.c4.service.module.datacenter.DCAsyncCommand;


public class CreateAccountDataAsync extends DCAsyncCommand{

	/**
	 * 
	 */
	protected AccountDataManager dataManager;
	
	/**
	 * 
	 */
	@SuppressWarnings("unused")
	private static final Log log = LogFactory.getLog(CreateAccountDataAsync.class);
	
	
	public void setDataManager(AccountDataManager dataManager) {
		this.dataManager = dataManager;
	}
	

	@Override
	public void asyncExecute() {

		Account acc = (Account) dataInfo.getData();
		GameUtility.writeCashUpdateConsoleLog("CreateAccountDataAsync.asyncExecute()", acc.getAccountId()
				.toString(), 0, 0, acc.getCash());
		boolean flag = AccountDAO.saveAccount(acc);
		
		if (flag) {
			resultCode = ResultNo.OK;
		} else {
			resultCode = ResultNo.DB_OPERATION_FAILED;
		}
	}

	@Override
	public void execute() {

		if(dataManager != null){
			// callback
			dataManager.createDataCallback(resultCode, dataInfo, srcModuleID, dataInfo.getData());
		}		
	}
	
	
	
}
